/*
 * @Author: qianmingtian
 * @Date: 2020-07-10 16:59:12
 * @LastEditors: qianmingtian
 * @LastEditTime: 2020-07-10 17:44:26
 * @FilePath: \qianmingtian.github.io\code\java\sifan_zhaoyin\CountBigWord.java
 */
package sifan_zhaoyin;

import java.security.KeyStore.Entry;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;

import org.omg.CORBA.CharHolder;

public class CountBigWord {

    public static void main(String[] args) {

        String str = "dsagfdsASFdf dG DG fdsfaA";
        HashMap<Character, Integer> hashMap = new LinkedHashMap<>();

        char[] buff = str.toCharArray();

        // 统计
        for (char c : buff) {
            if (c - 'A' >= 0 && c - 'Z' <= 0) {

                if (hashMap.containsKey(c)) {
                    hashMap.put(c, hashMap.get(c) + 1);
                } else {
                    hashMap.put(c, 1);
                }
            }
        }

        // 遍历
        Set<Character> set = hashMap.keySet();

        // 迭代器遍历方法
        Iterator<Character> it = set.iterator();
        while (it.hasNext()) {
            Character key = it.next();
            int value = hashMap.get(key);
            System.out.println(key + ":" + value);
        }
        System.out.println("-----------");
        // foreach 方法
        for (char c : set) {
            System.out.println(c + ":" + hashMap.get(c));

        }

        System.out.println("-----------");

        // 遍历
        Set<Map.Entry<Character, Integer>> sets = hashMap.entrySet();

        for (Map.Entry<Character, Integer> e : sets) {
            System.out.println(e.getKey() + ":" + e.getValue());
        }

    }

}/*
  * @Author: qianmingtian
  * 
  * @Date: 2020-07-10 16:59:12
  * 
  * @LastEditors: qianmingtian
  * 
  * @LastEditTime: 2020-07-10 16:59:12
  * 
  * @FilePath: \qianmingtian.github.io\code\java\Compare\CountBigWord.java
  */
